/**
 * Copyright (c) 2024 - CARThunder
 * All Rights Reserved by Chengdu CARThunder Intelligent Technology Co., LTD and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with CARThunder in writing by applicable law.
 *
 */

/**
 * file description.
 * @file    filename
 * @brief   brief function description.
 * @details detailed function description.
 * @version 1.0
 * @author  author_name
 * @date    last_modified_date
 *
 *      Edit History
 *      ----------------------------------------------------------------------------
 *      DATE                     NAME               DESCRIPTION
 *      2024-08-2               jia fengyi         Create it.
 *
 */

package com.cart.musicdemo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.request.RequestOptions;
import com.cart.musicdemo.R;
import com.cart.musicdemo.base.utils.FileUtils;
import com.cart.musicdemo.fragment.AlbumFragment;
import com.cart.musicdemo.model.SongModel;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * The type Album adapter.
 */
public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {

    private List<String> mData;

    private AlbumAdapter.OnItemClickListener listener;
    //通过key获取对应专辑歌曲
    private Map<String,List<SongModel>> albumMap;

    private Context context;

    /**
     * The interface On item click listener.
     */
    public interface OnItemClickListener {
        /**
         * On item click.
         *
         * @param name the name
         */
        void onItemClick(String name);
    }

    /**
     * Instantiates a new Album adapter.
     *
     * @param data              the data
     * @param itemClickListener the item click listener
     * @param albumMap          the album map
     * @param context           the context
     */
    public AlbumAdapter(List<String> data,
                        AlbumAdapter.OnItemClickListener itemClickListener,
                        Map<String,List<SongModel>> albumMap,
                        Context context) {
        this.mData = data;
        this.listener = itemClickListener;
        this.albumMap = albumMap;
        this.context = context;
    }

    /**
     * Instantiates a new Album adapter.
     *
     * @param data the data
     */
    public AlbumAdapter(List<String> data) {
        this.mData = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_album_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(mData.get(position));
        holder.relativeLayout.setOnClickListener(v -> listener.onItemClick(mData.get(position)));
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    /**
     * The type View holder.
     */
    public class ViewHolder extends RecyclerView.ViewHolder {
        /**
         * The Text view.
         */
        TextView textView;

        /**
         * The Relative layout.
         */
        RelativeLayout relativeLayout;


        /**
         * Instantiates a new View holder.
         *
         * @param itemView the item view
         */
        public ViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_albumTitle);
            relativeLayout = itemView.findViewById(R.id.rl_album_click);
        }
    }
}